package com.tc.controller;

import com.tc.entity.UserWithDeptExportVo;
import com.tc.excel.JxlExcelUtils;
import com.tc.excel.anno.RequestExcel;
import com.tc.excel.anno.ResponseExcel;
import com.tc.excel.enums.ExcelContentType;
import com.tc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Auther: tianchao
 * @Date: 2025/2/15 11:15
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/exportUser")
    @ResponseExcel(excelName = "用户列表",sheetName = "用户列表",excelSuffix= ExcelContentType.XLSX)
    public List<UserWithDeptExportVo> exportUser() {
        return userService.getUserWithDeptVo();
    }

    @RequestMapping("/exportUser2")
    public void exportUser2(HttpServletResponse response) {

        JxlExcelUtils.exportFileToResponses(
                userService.getUserWithDeptVo(),
                UserWithDeptExportVo.class ,
                "用户列表2",
                "用户列表2",
                ExcelContentType.XLS,
                response
               );
    }

    @RequestMapping("/importUser")
    public List<UserWithDeptExportVo> importUser(@RequestExcel(fileName = "hideFile") List<UserWithDeptExportVo> list) {
        return list;
    }



}
